@include("admin.layout.head")
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input class="layui-input" placeholder="开始日" value="{{$request->start}}" name="start" id="start">
            <input class="layui-input" placeholder="截止日" value="{{$request->end}}" name="end" id="end">
            <input type="text" name="name" placeholder="请输入用户名" value="{{$request->name}}" autocomplete="off" class="layui-input">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量停用</button>
        <span class="x-right" style="line-height:40px">共有数据：{{$users->total()}} 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                            class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>用户名</th>
            <th>手机</th>
            <th>加入时间</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

        @foreach($users as $user)
            <tr>
                <td>
                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{{$user->id}}'><i
                                class="layui-icon">&#xe605;</i></div>
                </td>
                <td>{{$user->id}}</td>
                <td>{{$user->name}}</td>
                <td>{{$user->phone}}</td>
                <td>{{$user->created_at}}</td>
                <td class="td-status">
                    <span class="layui-btn layui-btn-normal layui-btn-mini @if($user->status ==0) layui-btn-disabled @endif">@if($user->status ==1 )
                            已启用 @else 已停用 @endif </span></td>
                <td class="td-manage">
                    <a onclick="member_stop(this,{{$user->id}})" href="javascript:;" title="@if($user->status ==1)启用@else 停用 @endif">
                        <i class="layui-icon">@if($user->status ==1)&#xe601;@else&#xe62f;@endif </i>
                    </a>
                    </a>
                </td>
            </tr>
        @endforeach
        </tbody>
    </table>
    <div id="pull_right">
        <div class="pull-right">
            {!! $users->appends($request->all())->links() !!}
        </div>
    </div>
</div>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    /*用户-停用*/
    function member_stop(obj, id) {
        layer.confirm('确认要修改吗？', function (index) {

            $.ajax({
                url:"/admin/delUser/"+id,
                type:"post",
                dataType:"json"
            });
            if ($(obj).attr('title') == '启用') {
                //发异步把用户状态进行更改
                $(obj).attr('title', '停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!', {icon: 5, time: 1000});

            } else {
                $(obj).attr('title', '启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!', {icon: 5, time: 1000});
            }

        });
    }
    function delAll(argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要修改吗？' + data, function (index) {
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                url:"/admin/delUserAll",
                type:"post",
                data:{data:data},
                dataType:"json"
            });
            layer.msg('修改成功', {icon: 1});
            location.reload();
        });
    }
</script>
</html>